package leetcode.code021.MergeTwoSortedLists;

import leetcode.IDebug;
import leetcode.helper.tree.ListNode;

public class Solution02101 extends MergeTwoSortedLists {

	@Override
	public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
		if (l1 == null)
			return l2;
		if (l2 == null)
			return l1;
		ListNode head = new ListNode();
		ListNode p = head;
		while (l1 != null && l2 != null) {
			if (l1.val < l2.val) {
				p.next = l1;
				l1 = l1.next;
			} else {
				p.next = l2;
				l2 = l2.next;
			}
			p = p.next;
		}
		if (l1 == null) {
			p.next = l2;
		}
		if (l2 == null) {
			p.next = l1;
		}
		return head.next;
	}

	public static void main(String[] args) {
		IDebug so = new Solution02101();
		so.debug1();
		so.debug2();
		so.debug3();
	}

}
